package com.ruoyi.web.core.service;

import com.ruoyi.common.utils.ftp.FtpUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class FtpService {
    @Value("${ftp.server}")
    private String FTP_SERVER;// = "localhost";//"10.20.0.102";
    @Value("${ftp.port}")
    private int FTP_PORT;// = 21;
    @Value("${ftp.user}")
    private String FTP_USER;// = "1";
    @Value("${ftp.password}")
    private String FTP_PASSWORD;// = "1";

    public boolean uploadFileToFtp(String localFilePath, String remoteFilePath) {
        FtpUtil ftpUtil = new FtpUtil(FTP_SERVER, FTP_PORT, FTP_USER, FTP_PASSWORD);
        return ftpUtil.uploadFile(localFilePath, remoteFilePath);
    }

    public boolean downloadFileFromFtp(String remoteFilePath, String localFilePath) {
        FtpUtil ftpUtil = new FtpUtil(FTP_SERVER, FTP_PORT, FTP_USER, FTP_PASSWORD);
        return ftpUtil.downloadFile(remoteFilePath, localFilePath);
    }

    public boolean deleteFileFromFtp(String remoteFilePath) {
        FtpUtil ftpUtil = new FtpUtil(FTP_SERVER, FTP_PORT, FTP_USER, FTP_PASSWORD);
        return ftpUtil.deleteFile(remoteFilePath);
    }

    public boolean renameFileFormFtp(String oldRemoteFilePath, String newRemoteFilePath) {
        FtpUtil ftpUtil = new FtpUtil(FTP_SERVER, FTP_PORT, FTP_USER, FTP_PASSWORD);
        return ftpUtil.renameFile(oldRemoteFilePath, newRemoteFilePath);
    }
}